package com.example.common.utils;

import android.content.Intent;

import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.example.common.interfaces.ActivityResultCallback;

public class ProcessResultUtils {
    protected ProcessFragment mFragment;

    public ProcessResultUtils(FragmentActivity activity) {
        mFragment = new ProcessFragment();
        FragmentManager fragmentManager = activity.getSupportFragmentManager();
        FragmentTransaction ft = fragmentManager.beginTransaction();
        ft.add(mFragment, "ProcessFragment").commit();
    }

    public void requestPermissions(String[] permissions, Runnable runnable) {
        mFragment.requestPermissions(permissions, runnable);
    }

    public void startActivityForResult(Intent intent, ActivityResultCallback callback) {
        mFragment.startActivityForResult(intent, callback);
    }

    /**
     * 释放对象
     */
    public void release() {
        if (mFragment != null) {
            mFragment.release();
        }
    }

}
